package com.sanwei.taskmanagement.controller;

import com.sanwei.taskmanagement.model.User;
import com.sanwei.taskmanagement.service.impl.UserServiceImpl;
import com.sanwei.taskmanagement.util.AjaxResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Optional;

@RestController
@RequestMapping("/user")
public class UserController {
    @Resource
    private UserServiceImpl userService;

    /**
     * 查询UserList
     * @return userlist
     */
    @GetMapping("/list")
    public List<User> selectUserList() {
        List<User> userList = userService.selectUserList();
        return userList;
    }

    @GetMapping("/info")
    public AjaxResult getUserInfoByUsername(@RequestParam("username") String username) {
        User user = userService.getUserInfoByUsername(username);
        if (user == null) {
            return AjaxResult.error("用户查询失败");
        }
        return AjaxResult.success("用户查询成功",user);
    }
}
